<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%@include file="../../common/mastertopedit.jsp"%>
<script type="text/javascript" src="${ctx}/js/region.js"></script>
<input type="hidden" id="factoryId" value="${model.factoryId}">
<div class="form-horizontal pt-15  form-clean-magin" id="content">
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">供应商编码</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="factoryCode" id="factoryCode" maxlength="100" type="text"  pattern="/[^a-zA-Z\d]+/"
				<c:if test="${model.factoryInfo.id!=null}">disabled="disabled"</c:if>
				value="${model.factoryInfo.factoryCode}"> <i
				class="plum-sign-right">*</i>
		</div>
	</div>
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">供应商名称</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="factoryName" id="factoryName" maxlength="100" type="text"
				value="${model.factoryInfo.factoryName}"> <i
				class="plum-sign-right">*</i>
		</div>
	</div>
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">供应商简称</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="factoryShortName" id="factoryShortName" maxlength="100" type="text"
				value="${model.factoryInfo.factoryShortName}"> 
		</div>
	</div>
	<c:if test="${model.factoryInfo.id==null}">
		<div class="form-group">
			<label class="col-xs-3 text-right control-label usual-label">是否生成仓库</label>
			<div class="col-xs-9">
				<label class="radio-inline"> <input name="isGenerateStock"  type="radio" value="1">是</label> 
				<label class="radio-inline"> <input name="isGenerateStock"  type="radio" value="0">否</label>
			</div>
		</div>
		<div class="form-group">
			<label for="inputEmail3"
				class="col-xs-3 text-right control-label usual-label">仓库编码</label>
			<div class="col-xs-9">
				<input class="form-control form-control-260 pull-left" type="text"
					name="stockCode" id="stockCode" maxlength="100" type="text"> <i
					class="plum-sign-right">*</i>
			</div>
		</div>
			<div class="form-group">
			<label for="inputEmail3"
				class="col-xs-3 text-right control-label usual-label">仓库名称</label>
			<div class="col-xs-9">
				<input class="form-control form-control-260 pull-left" type="text"
					name="stockName" id="stockName" maxlength="100" type="text"> <i
					class="plum-sign-right">*</i>
			</div>
		</div>
	</c:if>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">联系人</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="factoryContacts" id="factoryContacts" maxlength="100" type="text"
				value="${model.factoryInfo.factoryContacts}"> 
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">手机号码</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="mobile" id="mobile" maxlength="20" type="text"
				value="${model.factoryInfo.mobile}" pattern="/[^\d]+/" > 
		</div>
	</div>
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">座机</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="tel" id="tel" maxlength="20" type="text"
				value="${model.factoryInfo.tel}"> 
		</div>
	</div>
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">地址</label>
		<div class="col-xs-9">
			<input type="hidden" id="pid" value="${model.factoryInfo.provinceId}">
			<input type="hidden" id="cid" value="${model.factoryInfo.cityId}">
			<input type="hidden" id="aid" value="${model.factoryInfo.areaId}">
			<select id="provinceId" class="form-control form-control-125 pull-left"   onchange="selectProvince()" >
				<option value="" >选择市</option>
			</select>
			<select id="cityId" class="form-control form-control-125 pull-left" onchange="selectCity()" >
				<option value="" >选择市</option>
			</select>
			<select id="areaId" class="form-control form-control-125 pull-left"  >
				<option value="" >选择市</option>
			</select>
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">详细地址</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="adress" id="adress" maxlength="100" type="text"
				value="${model.factoryInfo.adress}"> 
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">付款账期</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="settleMonth" id="settleMonth" maxlength="2" type="text"
				value="${model.factoryInfo.settleMonth}" pattern="/[^\d]+/" > 
				<i class="plum-sign-right">*</i>
				<p class="line-tips">天</p>
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">备注</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="remark" id="remark" maxlength="100" type="text"
				value="${model.factoryInfo.remark}"> 
		</div>
	</div>
</div>

<div class="form-group text-center">
	<button type="button" class="runmi-btn runmi-primary"
		onclick="backIndex()">取消</button>
	<button type="button" class="runmi-btn runmi-sure-btn" onclick="save()">保存</button>
</div>
<script type="text/javascript">
  function save(){	  
  		var factoryId=$('#factoryId').val();	
		var postData="factoryId=" +factoryId ;
		
		var factoryCode=$('#factoryCode').val();
		if(factoryCode==''){
			layer.alert('请输入供应商编号');
	    	return;
		}
		postData=postData + "&factoryCode=" + encodeURIComponent(factoryCode);
		
		var factoryName=$('#factoryName').val();
		if(factoryName==''){
			layer.alert('请输入供应商名称');
	    	return;
		}
		postData=postData + "&factoryName=" + encodeURIComponent(factoryName);
		
		var factoryShortName=$('#factoryShortName').val();
		postData=postData + "&factoryShortName=" + encodeURIComponent(factoryShortName);
		
		var isGenerateStock=$("input[name='isGenerateStock']:checked").val();
		postData=postData + "&generateStock=" + encodeURIComponent(isGenerateStock);
		
		var stockCode=$('#stockCode').val();
		postData=postData + "&stockCode=" + encodeURIComponent(stockCode);
		
		var stockName=$('#stockName').val();
		postData=postData + "&stockName=" + encodeURIComponent(stockName);
		
		//alert(isGenerateStock);
		if(isGenerateStock==undefined || isGenerateStock=='0'){
			
		}else{
			if(stockCode=='' || stockName==''){
				layer.alert('请输入仓库信息');
		    	return;
			}
		}
		
		var settleMonth=$('#settleMonth').val();
		if(settleMonth==''){
			layer.alert('请输入付款周期');
	    	return;
		}
		postData=postData + "&settleMonth=" + encodeURIComponent(settleMonth);
		
		var factoryContacts=$('#factoryContacts').val();
		postData=postData + "&factoryContacts=" + encodeURIComponent(factoryContacts);
		
		var mobile=$('#mobile').val();
		postData=postData + "&mobile=" + encodeURIComponent(mobile);
		
		var tel=$('#tel').val();
		postData=postData + "&tel=" + encodeURIComponent(tel);
		
		var provinceId=$('#provinceId').val();
		postData=postData + "&provinceId=" + encodeURIComponent(provinceId);
		
		var cityId=$('#cityId').val();
		postData=postData + "&cityId=" + encodeURIComponent(cityId);
		
		var areaId=$('#areaId').val();
		postData=postData + "&areaId=" + encodeURIComponent(areaId);
		
		var adress=$('#adress').val();
		postData=postData + "&adress=" + encodeURIComponent(adress);
		
		var remark=$('#remark').val();
		postData=postData + "&remark=" + encodeURIComponent(remark);
		
		
		var url="saveFactoryInfo";
		if(factoryId!=''){
			url="updateFactoryInfo";
		}
	
	    layer.load(1, {shade: [0.5,'#fff']});
	   // alert(url + postData);
	    $.ajax({
	        type: "POST",
	        url: url,
	        data: postData,
	        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	        async: true, // 同步  true 异步。默认是异步
	        dataType: 'json',
	        error: function(resultdata) {
	        	layer.closeAll();
	        },
	        success: function(resultdata) {
	        	layer.closeAll();
	            if(resultdata.returnCode=="0000"){               	
	            	layer.alert('操作成功',{icon: 1}, function(){
	            	 	 parent.editReturn();
	            	});
	            }else{
	            	layer.alert(resultdata.returnMessage);
	            }
	        }
	    });
	}
  function backIndex(){	  
 	 parent.editReturn();
  }
	</script>
<%@include file="../../common/masterbottom.jsp"%>
